import java.awt.Point;
import java.util.ArrayList;


public class PlayerTeam {
	private ArrayList<Character> team;
	private String name;

	public PlayerTeam(){
		name = "Player Team";
		team = new ArrayList<Character>();
	}

	public ArrayList<Character> getTeam(){
		return team;
	}
	
	public void add(Character x){
		x.setTeam(name);
		team.add(x);
	}
	
	public String getName(){
		return name;
	}
	
	public void remove(Character x){
		team.remove(x);
	}
	
	public boolean isTurnDone(EnemyTeam x, Tile[][] tilegrid, String[] map){
		for(Character i : team){
			if(!i.getActed())
				return false;
		}
		for(Character i : team){
			i.justActed(false);
		}
		System.out.println("Turn is over!");
		System.out.println(x);
		x.act(this, map);
		return true;
	}
	
	public Character isClicked(Character selectedChar, Tile[][] tilegrid){
		Character clickedChar = null;
		for(Character i : team){
			if(i.selected(tilegrid) != null && !i.equals(selectedChar))
        		clickedChar = i;
				i.unSelected();
		}

		return clickedChar;	
	}
	
	public ArrayList<Point> getLocations(){
		ArrayList<Point> locs = new ArrayList<Point>();
		for(Character i : team){
			locs.add(i.getPosition());
		}
		return locs;
	}
	
	public Point getAverageLocation(){
		ArrayList<Point> locs = getLocations();
		int xtotal = 0;
		int ytotal = 0;
		int count = 0;
		for(Character i : team){
			xtotal += i.getPositionX();
			ytotal += i.getPositionY();
			count++;
		}
		if(count>0){
			xtotal = xtotal/count;
			ytotal = ytotal/count;
		}
		else{
			System.out.println("You Lose!");
			return null;
		}
		return new Point(xtotal, ytotal);
	}
	
	public ArrayList<Point> getOccupiedLocations(EnemyTeam y){
		ArrayList<Point> occupied = new ArrayList<Point>();
		for(Character c : team){
			occupied.add(c.getPosition());
		}
		for(Character x : y.getTeam()){
			occupied.add(x.getPosition());
		}
		return occupied;
	}
	

	public String toString(){
		String output = "Team: " + name;
		for(Character i: team){
			output += "\n   " + i.getName();
		}
		
		return output;
	}





}

